import {createAction} from "redux-actions";
import {call, put} from "redux-saga/effects";
import {getPatient} from "../../../utils/RequestUtils";
import {APPOINTMENT_CONFIRM, PASS_DOCTOR, PATIENT_CHOOSE, PATIENT_LIST, PATIENT_LIST_FETCH} from "../../types";
// 获取科室列表
export const patientList = createAction(PATIENT_LIST, (data: []) => {
    return {data};
});


export const patientListFetch = createAction(PATIENT_LIST_FETCH, (params: object) => {
    return {...params};
});

export const appointmentConfirm = createAction(APPOINTMENT_CONFIRM, (params: object) => {
    return {...params};
});

export const patientChoose = createAction(PATIENT_CHOOSE, (patient: object) => {
    return {patient};
});

export const passDoctor = createAction(PASS_DOCTOR, (data: object) => {
    return {data};
});


export function* requestPatientList(params: object) {
    yield put(patientList([]));
    const fetchedData = yield call(getPatient, params);
    yield put(patientList(fetchedData.data));
}


export function* requestAppointmentConfirm(params: object) {
    yield put(patientList([]));
    const fetchedData = yield call(getPatient, params);
    yield put(patientList(fetchedData.data));
}